package suse.hotel.admin.admin.Controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import suse.hotel.admin.admin.DTO.AdminDTO;
import suse.hotel.admin.admin.DTO.UserDTO;
import suse.hotel.admin.admin.Mapper.AdminMapper;
import suse.hotel.admin.admin.Service.AdminService;

@Controller
public class AdminController {
    @Autowired
    AdminService adminService;
    @Autowired
    AdminMapper adminMapper;

    @RequestMapping("/addAdmin")
    @ResponseBody
    public void addAdmin(String username,String pass){
        adminMapper.addAdmin(username,pass);
    }
    @RequestMapping("/admin-add")
    public String toAddAdmin(){
        return "admin-add";
    }

    @RequestMapping("/delAdmin")
    @ResponseBody
    public String delAdmin(int id){
        int re=adminMapper.delAdmin(id);
        if(re!=0)
            return "true";
        return "false";
    }
    @RequestMapping("/selAdmins")
    @ResponseBody
    public String selUsers(@RequestParam(defaultValue="1") int page, @RequestParam(defaultValue="10") int limit) {
        return adminService.selAdmins(page,limit);
    }

    @RequestMapping("/editUser")
    @ResponseBody
    public int editUser(UserDTO userDTO) {
        int re= adminMapper.editUser(userDTO);
        return re;
    }
    @RequestMapping("/editAdmin")
    @ResponseBody
    public int editAdmin(AdminDTO admin) {
        int re= adminMapper.editAdmin(admin);
        return re;
    }
}
